package com.woniuxy.service.impl;


import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.woniuxy.entity.Log;
import com.woniuxy.mapper.LogMapper;
import com.woniuxy.service.LogService;

import lombok.Data;



import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dto.PageDto;
import com.woniuxy.entity.Log;
import com.woniuxy.entity.Orders;
import com.woniuxy.entity.Product;
import com.woniuxy.entity.User;
import com.woniuxy.mapper.LogMapper;
import com.woniuxy.service.LogService;


@Service
public class LogServiceImpl implements LogService{
	@Autowired
	LogMapper logmapper;
	
	@Autowired
	private LogMapper logMapper;

	@Override
	public List<Log> findLog() {

		return logMapper.findLog();
	}

	@Override
	public int addLog(int u_id, String content, String object, Date time) {

		return logMapper.addLog(u_id, content, object, time);
	}

	@Override
	public int delLog(int l_id) {

		return logMapper.delLog(l_id);
	}
	
	
	
	//查询卖家订单日志	public PageDto<Orders> findsellerorders(int u_id,int page) {
	@Override
	public int addorderLog() {
		
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user  = (User)session.getAttribute("user");
		
		Log log = new Log().setU_id(user.getU_id()).setContent("查询了一个订单").setObject("花瓶").setTime(new Date());
		
		
		return logmapper.addorderLogbuyer(log);
	}





	@Override
	public int addorderLogbuyer( String order_no) {
		
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user  = (User)session.getAttribute("user");
		
		Log log = new Log().setU_id(user.getU_id()).setContent("删除了一个订单").setObject( order_no ).setTime(new Date());
		
		System.out.println(order_no);
		return logmapper.addorderLogbuyer(log);
	}





	@Override
	public int insertgoodsInFo(Product product) {
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user  = (User)session.getAttribute("user");
		
		Log log = new Log().setU_id(user.getU_id()).setContent("上架了一个商品").setObject( product.getName() ).setTime(new Date());
		
		
		return logmapper.addorderLogbuyer(log);
	}





	@Override
	public PageDto<Log> findAllByuid(int uid, int page,String uname) {
		System.out.println("当前用户id是"+uid);
		System.out.println("当前用户id是"+uname);
		List<Log> log= new ArrayList();
		
		
		PageHelper.startPage(page, 5);
		log =logmapper.findAllByuid(uid);
		PageInfo<Log> pageInfo = new PageInfo<>(log);
		

		PageDto pageDto = new PageDto();
		pageDto.setCurrentPage(page); // 当前页
		pageDto.setPageSize(5); // 每一页大小
		pageDto.setTotal(pageInfo.getTotal()); // 总条数
		pageDto.setTotalPages(pageInfo.getPages()); // 总页数
		pageDto.setData(log); // 商品数据
		pageDto.setUname(uname);
		
		
		return pageDto;
	}




	//商家商品添加日志
	@Override
	public int uploadProduct(Product product) {
		
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user  = (User)session.getAttribute("user");
		
		Log log = new Log().setU_id(user.getU_id()).setContent("上架商品被驳回").setObject( product.getName() ).setTime(new Date());
		
		
		
		return logmapper.addorderLogbuyer(log);
	}




	
	

	

	
	
	
	


}
